﻿using System;

using System.Collections.Generic;
using System.Text;
using System.Collections;

namespace Silvermoon.Controls.Classes
{
    public enum GridUnitType
    {
        Auto,
        Fixed,
        Dynamic
    }

    public struct GridUnit
    {
        object value;
        public int Fixed { get { return (int)value; } }
        public float Dynamic { get { return (float)value; } }
        public GridUnitType Type;

        public GridUnit(int value)
        {
            this.Type = GridUnitType.Fixed;
            this.value = value;
        }

        public GridUnit(float value)
        {
            this.value = value;
            Type = GridUnitType.Dynamic;
        }
    }

    public class GridUnitCollection : IEnumerable
    {
        private System.Collections.ArrayList list = new System.Collections.ArrayList();

        public void AddRange(params object[] values)
        {
            foreach (object v in values) Validate(v);
            list.AddRange(values);
        }

        public void Clear()
        {
            list.Clear();
        }

        public object this[int index]
        {
            get
            {
                if (index >= list.Count) throw new IndexOutOfRangeException();
                return list[index];
            }
            set
            {
                if (index >= list.Count) throw new IndexOutOfRangeException();
                Validate(value);
                list[index] = value;
            }
        }

        public int Count { get { return list.Count; } }

        private void Validate(object value)
        {
            if (!(value is int) && !(value is float)) throw new InvalidCastException();
        }

        #region IEnumerable Members

        public IEnumerator GetEnumerator()
        {
            return list.GetEnumerator();
        }

        #endregion
    }


}
